<?php

namespace App\System\Cis\Repositories;

use App\System\Base\Helpers\Traits\SinglePattern;
use App\System\Base\Repositories\Repository;
use App\System\Cis\Model\CisUserPartner;

class CisUserPartnerRepository extends Repository
{
    use SinglePattern;

    /*
     * 根据主用户ID获取详情
     */
    public function getDetailByUserId($id)
    {
        if (!$id) {
            return false;
        }
        return CisUserPartner::where('user_id', $id)->first();
    }

    /*
     * 根据用户系统用户Id获取详情
     */
    public function getDetailByOpenId($openId)
    {
        if (!$openId) {
            return false;
        }
        return CisUserPartner::where('open_id', $openId)->first();
    }

    /**
     * 生成第三方帐号
     * @param $set array
     * @return int
     */
    public function addData($set)
    {
        $res = CisUserPartner::create($set);
        if(!$res)
        {
            return false;
        }
        return $res->id;
    }
}